﻿// <copyright file="ErrorWindow.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2010-04-11</date>
// <summary>ErrorWindow code behind</summary>

namespace DemoNavigation
{
    using System;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// ErrorWindow class definition
    /// </summary>
    public partial class ErrorWindow : ChildWindow
    {
        /// <summary>
        /// Initializes a new instance of the ErrorWindow class
        /// </summary>
        /// <param name="e">the exception</param>
        public ErrorWindow(Exception e)
        {
            InitializeComponent();
            if (e != null)
            {
                ErrorTextBox.Text = e.Message + Environment.NewLine + Environment.NewLine + e.StackTrace;
            }
        }

        /// <summary>
        /// Initializes a new instance of the ErrorWindow class.
        /// </summary>
        /// <param name="uri">the page URI</param>
        public ErrorWindow(Uri uri)
        {
            InitializeComponent();
            if (uri != null)
            {
                ErrorTextBox.Text = "Page not found: \"" + uri.ToString() + "\"";
            }
        }

        /// <summary>
        /// Initializes a new instance of the ErrorWindow class.
        /// </summary>
        /// <param name="message">the error message</param>
        /// <param name="details">the error details</param>
        public ErrorWindow(string message, string details)
        {
            InitializeComponent();
            ErrorTextBox.Text = message + Environment.NewLine + Environment.NewLine + details;
        }

        /// <summary>
        /// Close the dialog when the OK button is clicked
        /// </summary>
        /// <param name="sender">the OK Button</param>
        /// <param name="e">the routed event arguments</param>
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
    }
}